#include <iostream>
#include <string>
#include <algorithm>


inline char AdjustNum(int num) {
	if (num < 10) {
		return (char)(num + '0');
	}
	return (char)(num - 10 + 'A');
}


/**
 * 进制转换NOIP2000
 */
int main() {

	std::string result;

    int N;
    int R;

	std::cin >> N >> R;

	int NBak = N;
    while(N) {
		int residual = 0;
	    if (N > 0) {
            residual = N % (-R);
            N = (N - residual) / R;
	    }else {
		    if (-N % -R == 0) {
				N = N / R;
			}else {
				int nextN = N / R + 1;
				residual = N - nextN * R;
				N = nextN;
			}
	    }
		result += AdjustNum(residual);
    }

	std::reverse(result.begin(), result.end());
	std::cout << NBak << "=" << result << "(base" << R << ")";

    return 0;
}
